# 两种方法都可以
import heapq

class Solution:
    def lastStoneWeight(self, stones: List[int]) -> int:
        heap = [-v for v in stones]
        heapq.heapify(heap)
        while len(heap) > 1:
            heapq.heappush(heap, heapq.heappop(heap) - heapq.heappop(heap))
        return -heap[0]




class Solution:
    def lastStoneWeight(self, stones: List[int]) -> int:
        while len(stones) > 1:
            x = max(stones)
            stones.remove(x)
            y = max(stones)
            stones.remove(y)

            if x != y:
                stones.append(abs(x - y))
            else:
                stones.append(0)

        if len(stones) == 1:
            return stones[0]
        else:
            return 0


# 作者：aee2aeuaypcessa
# 链接：https: // leetcode - cn.com / problems / last - stone - weight / solution / whilexun - huan - yong - shi - ji - bai - 9325 - by - aee2aeuaypce /
# 来源：力扣（LeetCode）
# 著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。